export default {
  namespaced: true,
  state: {
    // 提示
    //   - msg 必须 提示内容
    //   - type 非必须 类型 success | info(默认) | error
    //   - show 必须 用于notice的手动点击消失
    systemNotice: []
  },
  mutations: {
    push (state, { msg, type = 'info', show = true }) {
      state.systemNotice.push({
        msg,
        type,
        show
      })
    },

    /**
     * @description 隐藏
     * @param {Object} state state
     */
    hide (state) {
      // state.systemNotice[state.systemNotice.length - 1].show = false
      state.systemNotice[0].show = false
    },

    /**
     * @description 清空
     * @param {Object} state state
     */
    pop (state) {
      state.systemNotice.pop()
    },

    /**
     * @description 清空
     * @param {Object} state state
     */
    shift (state) {
      state.systemNotice.shift()
    }
  },
  actions: {
    push ({ commit }, payload) {
      commit('push', payload)
      setTimeout(() => {
        commit('hide')
        setTimeout(() => {
          commit('shift')
        }, 100)
      }, 2000)
    }
  }
}
